package com.better.common.utils;

import com.better.backend.mqReceiverService.calType.model.CalTypeModel;
import com.better.consist.CalTypeEnum;

import java.math.BigDecimal;

/**
 * @author  获取平均分工具类
 * @create 2017-09-23 18:29
 **/
public class CalGetAvgUtil {

    public static Double getAgv(Double score,CalTypeModel calTypeModel){
        BigDecimal reAvg = new BigDecimal(score);
        Double reScore = new Double(0);
        if(CalTypeEnum.smallNum_one.equals(calTypeModel.getSmallNum())){
            reScore = reAvg.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        else if(CalTypeEnum.smallNum_two.equals(calTypeModel.getSmallNum())){
            reScore = reAvg.setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        else if(CalTypeEnum.smallNum_three.equals(calTypeModel.getSmallNum())){
            reScore = reAvg.setScale(2,BigDecimal.ROUND_UP).doubleValue();
        }
        else{
            reScore = reAvg.setScale(0,BigDecimal.ROUND_UP).doubleValue();
        }
        return reScore;
    }

    /**
     * 计算百分比得分，得分率
     * @param score
     * @param scoreNow
     */
    public static Double getRate(String score,String scoreNow){
        BigDecimal sco = new BigDecimal(score);
        BigDecimal scoNew = new BigDecimal(scoreNow);
        BigDecimal nowsco = scoNew.divide(sco,4,BigDecimal.ROUND_HALF_UP);
        return nowsco.multiply(new BigDecimal(100)).doubleValue();
    }

    public static void main(String[] args) {
        Double a = 92.11;
        String b = "100";
        System.out.println(getRate(b,a.toString()));
    }
}
